#!/bin/bash
# date: 2025/5/28
# desc: install rancher

# https://docs.rancher.cn/docs/rancher2/trending-topics/install-rancher-on-k8s/_index

install() {
    helm repo add rancher-latest https://releases.rancher.com/server-charts/latest
    helm repo update

    kubectl create namespace cattle-system

    kubectl -n cattle-system create secret tls tls-rancher-ingress \
        --cert=tls.crt \
        --key=tls.key

    helm install rancher rancher-latest/rancher \
        --namespace cattle-system \
        --set hostname=rancher.yourdomain.com \
        --set bootstrapPassword=admin@123 \
        --set ingress.tls.source=secret

    kubectl -n cattle-system rollout status deploy/rancher
    kubectl -n cattle-system get ingress
}

update_cert() {
    kubectl -n cattle-system create secret tls tls-rancher-ingress --cert=tls.crt --key=tls.key --dry-run=client -o yaml | kubectl apply -f -
    kubectl -n cattle-system rollout restart deployment rancher

}

uninstall() {
    helm uninstall rancher -n cattle-system
    kubectl delete namespace cattle-system
}
